<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('单据查询列表')" />
	<th:block th:include="include :: list-css" />
    <style>
       /* .layui-border-box{height: 400px !important;}
		.layui-table-body{height: 290px !important;} */
        .layui-tab-title{border-color: #ccc !important;}
        .layui-this{color: rgb(0, 135, 250) !important;background: none !important;}
        .layui-tab-brief > .layui-tab-title .layui-this:after, .layui-tab-brief > .layui-tab-more li.layui-this:after{border-color:  rgb(0, 135, 250) !important;}
        .mid-content {overflow: auto;}
        tr img{width: 30px !important;height: 30px !important;margin: 0 2px;}
        .ishide{display: none;}
        .bagimg{z-index: 999;max-width:200px;border: 5px solid #23b971}

        .layui-table-view .layui-table .layui-table-cell{
            height: auto !important;
        }

        .layui-table-tips-main img{margin: 10px;width: 200px;}


        /* .layui-table-body{overflow-y: auto;overflow-x: hidden;} */
        /* .layui-table-body{} */
    </style>
</head>
<body class="no-skin">
    <div class="ishide"><img class="bagimg" src=""/></div>



<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" th:if="${extraButton.addbtn}">
            <i class="dhicon dh-lujing1089"></i> 新增
        </div>
        <div class="layui-btn layui-table-tools importbtn-bg accountbtn" lay-event="accountbtn" th:if="${extraButton.accountbtn}">
            <i class="dhicon layui-icon-search"></i> 1688账户
        </div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" th:if="${extraButton.exportbtn}">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>
    <!-- 表格操作区 -->
    <script type="text/html" id="barDh">
        <a th:if="${extraButton.editbtn}" class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-edit" onclick="editbtn('{{d.guid}}','{{d.code}}')">&nbsp;修改</a>
        <a th:if="!${extraButton.editbtn}" class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-edit">&nbsp;修改</a>
    </script>

<script th:inline="javascript">
    /*<![CDATA[*/
    var gridColumns = [[${gridColumns}]],
        business = [[${purchase}]],
        buttonState = [[${buttonState}]],
        extraButton = [[${extraButton}]],
        businessName = gridColumns.moduleAlias,
        passwordAuthentication = [[${passwordAuthentication}]],
        moduleTable = [[${moduleTable}]];

    /*]]>*/
    var prefix = "/purchase/"+business;
	var tableUrl = prefix + "/list",
	openRowUrl = "/purchase/"+(business.split('/')[1]?business.split('/')[0]:business)+"/edit?nid=";
	exportUrl = prefix + "/export";
	var selectedUser = ""
	var pCode = ""
</script>
<th:block th:include="listinclude :: container" />
<th:block th:include="include :: footer" />
<th:block th:include="include :: tableBtn" />
<th:block th:include="listinclude :: list-templeat" />
<th:block th:include="include :: searchJS" />
<th:block th:include="include :: listJS" />
<script type="text/html"  id="templet_images"> 
    {{# 
        var delhtml = function(str) {
            return str.split('|')
        };
        var imgarr=delhtml(d.images);
        var str='';
        for(var i=0;i<imgarr.length;i++){
            if(imgarr[i]){
                str+=`<img name="${imgarr.length}" src="${imgarr[i]}"/>`;
            }
        }
        return str;
    }}
</script>
<script type="text/html" id="templet_sCode">
    <!-- <input type="text" value="{{d.sCode}}" readonly style="border: none;background: none;margin-right: 10px;"> -->
    <span style="margin-right: 20px;">{{d.sCode}}</span>
    <i class="layui-icon layui-icon-more" onclick="getMore('sCode','{{d.LAY_TABLE_INDEX}}','子件编码','tp_productactivecomponent',false,false,true)" style="position:absolute;right:8px;"></i>
</script>


<script th:inline="javascript">

	var $,layer,form,table;
    var data1688;
    layui.use(['table','laydate','form','layer','jquery','util','element','upload'], function () {
        $ = layui.$,layer = layui.layer,form = layui.form,laydate = layui.laydate,util = layui.util,element=layui.element,upload = layui.upload,table = layui.table;
		//头工具栏事件
        setTimeout(() => {
            table.on('toolbar(ftable)', function(obj){
 	            switch(obj.event){
                    case 'addbtn':
                        dialog('新增',prefix+ "/edit?guid=0",($(window).width()-500)>650?650:($(window).width()-500),($(window).height()-200)>610?610:($(window).height()-200),'addpost');
                        break;
                    case 'accountbtn'://1688账户
                        layer.open({
                	    	type: 2,
                	    	area: ['900px','450px'],
                	    	fix: false,//不固定
                	    	offset: '10%',//距离顶部
                	    	maxmin: true,//最大最小化
                	    	shade: 0.3,//遮罩
                	    	title: '1688账户',
                	    	content: "/purchase/distribution/account",
                	    	btn: ['取消'],
                	    	shadeClose: true,// 弹层外区域关闭
                	    });
	        		    break;
	   	        	case 'exportbtn':
		           		$.ajax({
		           		    url: '/purchase/distribution/export',
		           		    type: 'GET',
		           		    data: getWherestr(),
		           		    dataType: 'json',
		           		    beforeSend: function(){
		        	   			showloadings(true);
		           		    },
		           		    success: function(result){
		           		    	if (result.code == 0) {
		        			        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
		        			        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
		        				} else if (result.code == web_status.WARNING) {
		                           $.modal.alertWarning(result.msg)
		                    	} else {
		        					$.modal.alertError(result.msg);
		        				}
		        		   		showloadings(false);
		           		    }
		           		});
	   	        	break;
		        	case 'tableFull'://表格展开
		        		$('.north .layui-form').hide();
		        		table.reload('dhtable',{
		        			defaultToolbar: [{title:'收缩',layEvent:'tableShrink',icon:'layui-icon-screen-restore'}],
		        			height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
		        		});
		        	break;
		        	case 'tableShrink'://表格收缩
		        		$('.north .layui-form').show();
		        		table.reload('dhtable',{
		        			defaultToolbar: [{title:'展开',layEvent:'tableFull',icon:'layui-icon-screen-full'}],
		        			height: $(window).height()-$('.north').height()-60<300?'300':$(window).height()-( $('.north').height()+$('.south').height()+12)
		        		});
		        	break;
	 	            case 'fieldSet':
 	            		filedSet(moduleTable);
                  	break;
 	            };
 	        });
        }, 500);
        


        //新增修改弹出框
        window.dialog=function (title,url,width,height,Method){
            $.modal.open(title,url,width,height,function(index){
                var inputForm = $(window.frames["layui-layer-iframe" + index].document).contents().find(".layui-form");
                var is_return = 0,
                    // postStr = [],
                    must_field={},
                    Str = inputForm.serializeFormToJson();

                $.each(gridColumns.dictionaryForPageFieldList,function (fk,fv) {
                    if(fv.fieldFrontRequired)
                        must_field[fv.fields] = fv.fieldName + " 不能为空";
                })
                $.each(must_field,function (k,v) {
                    if(!inputForm.find("#"+k).val()){
                        layer.msg(v);
                        is_return = 1;
                        inputForm.find("#"+k).css('border','1px solid red');
                        inputForm.find("#"+k).focus()
                        return false;
                    }
                })
                if(is_return)return false;
                var deldata = {'infoItems':JSON.stringify(Str)};
                $.operate.post('/purchase/distribution/editpost',deldata,function(result){
                    allReload(result)
                });
            })
        }
        function allReload(result){
            if(result.code==0){
                setTimeout(function(){
                    layer.closeAll();
                    table.reload('dhtable');
                }, 1000);
            }
        }

        $(".getMore").click(function(){
            var data_for= $(this).attr('data-for');
            var selectedObject = $("#"+data_for).val();
        })
    });

    //弹出框修改
    function editbtn(guid){
        dialog('修改',prefix+ "/edit?guid="+guid,($(window).width()-500)>650?650:($(window).width()-500),($(window).height()-200)>610?610:($(window).height()-200),'addpost');
    }

</script>

<script>
    var zjgridColumns
    $('.zjbcbtn').show()

    function getMoreAfter(fieldsList,fields,tindex,fieldName,fieldSearchType,isSearch,isLayer,res){//弹出框赋值回调
       data1688[tindex].sCode=res.code
       data1688[tindex].pCode=res.pcode
       data1688[tindex].pName=res.pName
       data1688[tindex].sName=res.name
        scroll=GetPageScroll()
        // $.tablelist.init({
	    // 	elem: '#dhtable'
	    // 	,data: data1688
	    // 	,totalRow: gridColumns.totalRow
	    // 	,cols: [gridColumns.gridBody]
	    // 	,toolbar: '#toolbar'
	    // 	,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}]
        //     ,height:'full-46'
	    	
	    // });

        console.log("111")
        $.post(prefix+'/saveData',{'infoItem':JSON.stringify(data1688[tindex])}, function(res){
			// layer.msg(res.msg);
		});
        table.reload('dhtable',{page:{curr: pagenum}});
    }

    //  //头工具栏事件
	// $('.zjbcbtn').click(function(){
	// 	  $.post(prefix+'/saveData',{'infoItems':JSON.stringify(table.cache.pdhtable),'goodsID':table.cache.pdhtable.length>0 ?table.cache.pdhtable[0].goodsID :''}, function(res){
	// 		layer.msg(res.msg);
	// 	});
	// })


</script>
</body>
</html>